<?php

namespace app\admin\model;

use think\Model;
use app\admin\validate\Manager as ManagerValidate;
class Manager extends Model
{ 
    public function _initialize(){ 
        $validate =new ManagerValidate;
    }
    public function add($request){
        $data=array(
            'account' =>$request->param('account'),
             'password'=>md5($request->param('password')),
             'repassword'=>md5($request->param('repassword')),
             );
             $validate =new ManagerValidate;
            if(!$validate->scene('save')->check($data)){
                return $res=['code'=>0,'msg'=>$validate->getError()]; 
             }
             unset($data['repassword']);
             $this->insert($data);
             return $res=['code'=>1,'msg'=>'管理员添加成功']; 
    }
    public function edit($data, $id){
        $validate =new ManagerValidate;
            if(!$validate->scene('update')->check($data)){
                return $res=['code'=>0,'msg'=>$validate->getError()]; 
             }
             unset($data['repassword']);
             $this->where('id',$id)->update($data);
             return $res=['code'=>1,'msg'=>'管理员编辑成功']; 
    }
}
